package net.wanho.warehouse.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * Ajax响应结果对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "AjaxResult对象", description = "Ajax响应结果对象")
public class R implements Serializable {
    @ApiModelProperty("响应状态码")
    private Integer code;

    @ApiModelProperty("是否成功")
    private Boolean success;

    @ApiModelProperty("响应消息")
    private String message;

    @ApiModelProperty("响应数据")
    private Object data;

    public static R success(Integer code, String message, Object data){
        return new R(code, true, message, data);
    }

    public static R success(String message, Object data){
        return new R(200, true, message, data);
    }

    public static R success(Object data){
        return new R(200,true,  "success", data);
    }

    public static R success(){
        return new R(200,true,  "success", null);
    }

    public static R success(Integer code, String message){
        return new R(code,true,  message, null);
    }

    public static R success(Integer code){
        return new R(code,true,  "success", null);
    }

    public static R success(String message){
        return new R(200,true,  message, null);
    }

    public static R fail(Integer code, String message){
        return new R(code, false, message, null);
    }

    public static R fail(String message){
        return new R(500,false,  message, null);
    }
}
